﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace ImportDataCore
{
    public partial class UCInput : DevExpress.XtraEditors.XtraUserControl
    {
        UCLog _ucLog = null;

        public event RegisterLogToLogCenterEventHandler RegisterLogToLogCenter;

        public UCInput()
        {
            InitializeComponent();
            _ucLog = new UCLog();
            _ucLog.Dock = DockStyle.Fill;
            this.grpInputLog.Controls.Add(_ucLog);
        }

        public void ClearLog()
        {
            this._ucLog.ClearLog();
        }


        public void InitProgress(int max, int min, int step)
        {
            this.progressBarInput.Properties.Maximum = max;
            this.progressBarInput.Properties.Minimum = min;
            this.progressBarInput.Properties.Step = step;
            this.progressBarInput.Position = this.progressBarInput.Properties.Minimum;
            this.progressBarInput.Refresh();
        }

        public void NotifyProgress(int position, string log)
        {
            if (position < this.progressBarInput.Properties.Maximum
                || position > this.progressBarInput.Properties.Minimum)
            {
                this.progressBarInput.Position = position;
            }
            if (!string.IsNullOrEmpty(log))
            {
                this.lableTip.Text = "当前正在进行：" + log;
            }
            Application.DoEvents();
        }

        public void NotifyLogInfo(LogEventArgs logEventArgs)
        {
            if (logEventArgs == null)
                return;

            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append("\r\n");
            strBuilder.Append("............................");

            strBuilder.Append("\r\n");
            strBuilder.Append("当前时间：" + DateTime.Now.ToString());

            strBuilder.Append("\r\n");
            strBuilder.Append("当前时间：" + DateTime.Now.ToString());

            if (logEventArgs.IRowNum != -1)
            {
                strBuilder.Append("\r\n");
                strBuilder.Append("当前行：" + logEventArgs.IColNum.ToString());
            }

            if (logEventArgs.IColNum != -1)
            {
                strBuilder.Append("\r\n");
                strBuilder.Append("当前列：" + logEventArgs.IColNum.ToString());
            }

            if (!string.IsNullOrEmpty(logEventArgs.LogMsg))
            {
                strBuilder.Append("\r\n");
                strBuilder.Append("当前信息：" + logEventArgs.LogMsg);
            }

            strBuilder.Append("\r\n");
            strBuilder.Append("............................");

            this._ucLog.AddLog(strBuilder);
            RegisterLogArgsToLogInfo(logEventArgs, EnumOperaterType.input);
        }

        private void RegisterLogArgsToLogInfo(LogEventArgs logEventArgs,EnumOperaterType operaterType)
        {

            if (RegisterLogToLogCenter != null)
                RegisterLogToLogCenter(logEventArgs,operaterType);
        }
    }
}
